// packageE/title/title.js
var app = getApp();
Component({
  properties: {
    datas: {
      type: null,
    },
    storeList: {
      type: null,
    },
    showMun: {
      type: null,
    },
    plugin_active: String,
    is_sales_display: {
      type: null,
    }
  },
  // 私有数据，可用于模板渲染
  data: {
    emptyImage:  `${app.globalData.imgPath}image.png`,
    clientWidth: "375",
  },

  lifetimes: {
    // 生命周期函数，可以为函数，或一个在methods段中定义的方法名
    attached() {},
    moved() {},
    detached() {},
  },

  // 生命周期函数，可以为函数，或一个在methods段中定义的方法名
  attached() {},
  // 此处attached的声明会被lifetimes字段中的声明覆盖
  ready() {
    this.setData({
      clientWidth: wx.getSystemInfoSync().windowWidth,
    });
  },
  observers: {
    'storeList,datas': function (list, datas) {}
  },
  pageLifetimes: {
    // 组件所在页面的生命周期函数
    show() {},
    hide() {},
    resize() {},
  },
  methods: { // 跳转到店铺
    toRouter(e) {
      let item = e.currentTarget.dataset.item;
      if (item.specify_show == 1) {
        wx.navigateTo({
          url: "/packageC/o2o/o2oStore/o2oStore?store_id=" +
						item.id +
						"&fromHome=1",
        });
      } else {
        if (item.store_decorate == 1) {
          wx.navigateTo({
            url: "/packageG/o2o/HomeSeller/HomeSeller?store_id=" + item.id,
          });
        } else {
          wx.navigateTo({
            url: "/packageC/o2o/HomeSeller/HomeSeller?store_id=" + item.id,
          });
        }

      }
    },
    toPunch(e){
      let id = e.currentTarget.dataset.id;
      let urlStr = app.getNetAddresss("plugin.store-attendance.frontend.member.attendance");
      app._getNetWork({
        url: urlStr,
        data:{
          store_id:id
        },
        success: (resdata) => {
          var res = resdata.data;
          if (res.result == 1) {
            wx.showToast({
              title: res.msg,
              duration:1000,
              icon:'none'
            })
          } else {
            wx.showToast({
              title: res.msg,
              duration:1000,
              icon:'none'
            })
          }
        },
        fail: function (res) {
          // console.log(res);
        },
      });
    },
    toClassify(e) {
      let id = e.currentTarget.dataset.id;
      let name = e.currentTarget.dataset.name;
      wx.navigateTo({
        url: "/packageC/o2o/o2oCategory/o2oCategory?id=" +
					id +
					"&city=" +
					this.data.city +
					"&point=" +
					JSON.stringify(this.data.point) + '&name='+name,
      });
    },
    toGoods(e) {
      let item = e.currentTarget.dataset.item;
      wx.navigateTo({
        url: "/packageA/detail_v2/detail_v2?id=" + item.goods_id,
      });
    },
    // 打开地图
    goToAdress(e) {
      let latitude = e.currentTarget.dataset.items.latitude;
      let longitude = e.currentTarget.dataset.items.longitude;
      let store_name = e.currentTarget.dataset.items.store_name;
      let point = app.BMapTransqqMap(
        parseFloat(longitude),
        parseFloat(latitude)
      );
      wx.openLocation({
        latitude: point.lat,
        longitude: point.lng,
        scale: 18,
        name: store_name,
      });
    },
  },
});